<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>报名培训</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>

    <link rel="stylesheet" href="../js/libs/sui/sm.min.css">
    <link rel="stylesheet" href="../js/libs/sui/sm-extend.min.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <link rel="stylesheet" href="../less/main.css"/>
    <style>

    </style>
    <script type="text/javascript" src='../js/libs/jquery-3.1.0.min.js' charset='utf-8'></script>
    <script type="text/javascript">
        var Zepto = jQuery;
    </script>
    <script type="text/javascript" src='../js/libs/sui/sm.js' charset='utf-8'></script>
    <script type="text/javascript" src='../js/libs/sui/sm-extend.min.js' charset='utf-8'></script>
    <script type="text/javascript" src='../js/libs/sui/sm-city-picker.min.js' charset='utf-8'></script>
    <script type="text/javascript" src="../js/libs/juicer-min.js"></script>
    <script type="text/javascript" src="../js/libs/jquery.md5.js"></script>
    <script type="text/javascript" src="../js/api.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>
</head>
<body>
<!-- 这里是页面内容区 -->
<div class="content native-scroll p-t22 my-resume">
    <!--我的班级-->
    <!-- 头部-->
    <div class="head-no-toolbar bg-self-green no-left-icon">
        <span class="icon iconfont c-white p-l" onclick="javascript:api.closeWin();">&#xe61f;</span>
        <span class="c-white t-center">报名培训</span>
    </div>

    <!--内容区-->
    <div class="content-block">
        <div class="list-block">
            <form action="">
                <ul>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">姓名</div>
                                <div  class="item-input">
                                    <input id="name1" type="text" placeholder="请输入姓名">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">手机号</div>
                                <div class="item-input">
                                    <input type="number" id="registerNumber" placeholder="请输入手机号">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">身份证号</div>
                                <div class="item-input">
                                    <input type="text" id="shengfenzheng" placeholder="请输入身份证号">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">班级类型</div>
                                <div id="courseName" class="item-input c-default">
                                    安卓开发培训课程
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">学费</div>
                                <div id="fee-price" class="item-input c-default">
                                    ￥5950
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-gender"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">是否是在校生</div>
                                <div class="item-input">
                                    <input type="radio" name="stu" value="stuyes" id="stuyes"/>
                                    <label for="stuyes">是</label>
                                    <input type="radio" name="stu" value="stuno" id="stuno" style="margin-left: 10px;"/>
                                    <label for="stuno">否</label>
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label">推荐人</div>
                                <div class="item-input">
                                    <input type="text" id="registerMan" placeholder="请输入推荐人姓名">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-media"><i class="icon icon-form-name"></i></div>
                            <div class="item-inner">
                                <div class="item-title label" style="width: 6%;">
                                    <input type="checkbox" checked="true"/>
                                </div>
                                <div class="item-input f-time">
                                    预报名即视为同意<a href="#" class="c-red">《百马树用户报名协议》</a>
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </form>
        </div>
        <div class="content-block">
            <div class="row">
                <div id="registCommit" class="col-100"><a href="#" class="button button-big button-fill button-success">确认报名</a></div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    apiready = function () {
        juicer.set({
            'tag::operationOpen': '{@',
            'tag::operationClose': '}',
            'tag::interpolateOpen': '&{',
            'tag::interpolateClose': '}',
            'tag::noneencodeOpen': '$${',
            'tag::noneencodeClose': '}',
            'tag::commentOpen': '{#',
            'tag::commentClose': '}',
            'strip': false,
            'cache': false
        });


        var paraObj = api.pageParam;
        var studentObj = getLoginStudentInfo();

        if(isNotNull(paraObj)) {

            var sqlCommit = "INSERT INTO stu_enroll(STU_NAME, LINK_PHONE,ID_NUM,SCHOOL_FEE,CLASS_TYPE_ID, COURSE_ID, ORGAN_ID,CLASS_TYPE_NAME, ENROLL_DATE,REFEREE,STUDENT_ID,SCHOOL_FLAG)";
            sqlCommit += " VALUES('{0}','{1}','{2}','{3}','"+paraObj.classTypeId+"','{4}','{5}','{6}', NOW(),'{7}','{8}','{9}')";
            $("#courseName").text(paraObj.courseName);
            $("#fee-price").text("￥" + paraObj.tuition);

            $("#registCommit").on("click", function() {
                getRegistStu();
            });
        }
        if(isLogin()) {
            if(isNotNull(studentObj)) {
//                $("#name1").text(studentObj.STUDENT_NAME);
                $("#name1").val(studentObj.STUDENT_NAME);
                $("#registerNumber").val(studentObj.MOBILE_PHONE);
                $("#shengfenzheng").val(studentObj.ID_NUM);

                var schoolFlag = studentObj.SCHOOL_FLAG;
                if(schoolFlag == "1") {
                    $("#stuyes").attr("checked","checked");
                } else {
                    $("#stuno").attr("checked","checked");
                }
            }
        }
        function getRegistStu() {

            var stu_name =  $("#name1").val();
            var idNum =  $("#shengfenzheng").val();
            var courseName =  $("#courseName").text();
            var feeCourse = $("#fee-price").text();

            var phone = $("#registerNumber").val();
            var recommendName = $("#registerMan").val();

            if(isEmpty(phone)) {
                toast("请输入你的联系方式");
                return;
            }

            var flag = $('input[name="stu"]:checked ').val();

            if(flag === "stuyes") {
                flag = "1";
            } else if(flag === "stuno") {
                flag = "2";
            }
//            alert(paraObj.organId +" ," +  paraObj.courseId + "," + paraObj.classTypeId + "," + courseName + "," + stu_name + "," +  paraObj.tuition + "," + recommendName + "," +studentObj.STUDENT_ID + "," + flag );

            sqlCommit = sqlCommit.format(stu_name,phone,idNum,paraObj.tuition,paraObj.courseId,paraObj.organId, paraObj.courseName,recommendName,studentObj.STUDENT_ID,flag);

            dbExecute(sqlCommit,true,function(ret,err) {
                if (ret.statusCode == 0) {
                    toast("报名成功");

                    $("#registCommit").hide();

                } else {
                    toast("报名失败，稍后再试");

                }
            });
        }

    };
</script>
</body>
</html>
